package q2337_canChange;

public class Solution {
    /*
    移动片段得到字符串
    与q777完全相同的一题
     */
    public boolean canChange(String start, String target) {
        int n = start.length();
        int i = 0, j = 0;
        while (true) {
            while (i < n && start.charAt(i) == '_') ++i;
            while (j < n && target.charAt(j) == '_') ++j;
            if (i == n && j == n) return true;
            if (i == n || j == n || start.charAt(i) != target.charAt(j)) return false;
            if (start.charAt(i) == 'L' && i < j || start.charAt(i) == 'R' && i > j) return false;
            ++j;
            ++i;
        }
    }
}
